<template>
  <transition
    enter-active-class="animated fadeInUp"
    leave-active-class="animated fadeOutDown"
  >
    <div class="setting-wrapper" v-show="menuVisible && settingVisible === 1">
      <div class="setting-theme">
        <div
          class="setting-theme-item"
          v-for="(item, index) of themeList"
          :key="index"
          @click="setTheme(index)"
        >
          <div
            class="preview"
            :class="{'selected': item.name === defaultTheme}"
            :style="{background: item.style.body.background}"
          ></div>
          <div
            class="text"
            :class="{'selected': item.name === defaultTheme}"
          >{{ item.alias }}</div>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
import { ebookMixin } from '../../utils/mixin'
import { saveTheme } from '../../utils/localStroage'
export default {
  name: 'EbookSettingTheme',
  mixins: [ebookMixin],
  methods: {
    setTheme (index) {
      const theme = this.themeList[index]
      this.setDefaultTheme(theme.name).then(() => {
        this.currentBook.rendition.themes.select(this.defaultTheme)
        this.initGlobalStyle()
      })
      saveTheme(this.fileName, theme.name)
    }
  }
}
</script>

<style lang="stylus" scoped>
@import '../../assets/styles/global.styl'
.setting-wrapper
  background: white
  position: absolute
  bottom: px2rem(48)
  display: flex
  flex-direction: column
  left: 0
  z-index: 101
  width: 100%
  height: px2rem(90)
  box-shadow: 0 px2rem(-8) px2rem(8) rgba(0, 0, 0, .15)
  .setting-theme
    height: 100%
    width: 100%
    display: flex
    .setting-theme-item
      flex: 1
      display: flex
      // 垂直排布
      flex-direction: column
      padding: px2rem(5)
      box-sizing: border-box
      .preview
        flex: 1
        border: px2rem(1) solid #ccc
        // 盒子模型原理，添加边框后，宽高会变化
        box-sizing: border-box
      .selected
        box-shadow: 0 px2rem(4) px2rem(6) 0 rgba(0, 0, 0, .1)
      .text
        flex: 0 0 px2rem(20)
        font-size: px2rem(14)
        color: #ccc
        center()
      .selected
        color: #333
</style>
